package com.example.kcb;

import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import java.io.File;

/**
 * Created by Lenovo on 2018/12/1.
 */

public class DatabaseHelper extends SQLiteOpenHelper {
    private static final String DATABASE_NAME = "databases.db";
    private static final int DATABASE_VERSION = 2;
    public DatabaseHelper(Context context) {
        super(context, DATABASE_NAME, null, DATABASE_VERSION);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        db.execSQL("CREATE TABLE IF NOT EXISTS courses (" +
                "id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                "course_name TEXT, " +
                "teacher TEXT, " +
                "class_room TEXT, " +
                "day INTEGER, " +
                "period TEXT" +  // 确保这里有 period 列
                ");");

        // 创建课程记录表
        db.execSQL("CREATE TABLE IF NOT EXISTS course_records (" +
                "id INTEGER PRIMARY KEY AUTOINCREMENT, " +
                "course_name TEXT, " +
                "class_room TEXT, " +
                "teacher TEXT, " +
                "record_time TEXT, " +
                "period TEXT, " +
                "date INTEGER, " +
                "state INTEGER DEFAULT 0, " + // 0 表示未上课，1 表示已上课
                "course_id INTEGER " +
                ");");
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {
        System.out.printf("版本号" + newVersion);
        // 在这里处理数据库升级逻辑
        db.execSQL("DROP TABLE IF EXISTS courses");
        db.execSQL("DROP TABLE IF EXISTS course_records");
        onCreate(db);


    }

}